﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;

namespace PeisongWeb
{
    public partial class buyer_categoryCollectDetails :buyerPage
    {
        protected int cid
        {
            get
            {
                int tmp;
                try { tmp = Convert.ToInt32(ViewState["cid"]); }
                catch { tmp = 0; }
                return tmp;
            }
            set
            { ViewState["cid"] = value; }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (hasPermission("DC", 1))
                {
                    if (Request.QueryString["cid"] != null)
                    {
                        if (Library.Number.IsIntPositive(Request.QueryString["cid"]))
                        {
                            cid = Convert.ToInt32(Request.QueryString["cid"]);
                        }
                    }
                    if (cid != 0)
                    {
                        rptBind();
                    }
                    else
                    {
                        Response.Redirect("buyer_categoryCollect.html");
                        return;
                    }
                }
                else
                {
                    Library.Script.ClientMsgUrl("没有权限！", "buyer_index.html");
                    return;
                }
            }
        }

        void rptBind()
        {
            int companyId = logic.customer.getCompanyId();
            string type = logic.company.getById(companyId).Type;
            StringBuilder where = new StringBuilder();
            where.AppendFormat("categoryId = {0} and companyId={1}",cid,companyId);
            if (txt_orderNo.Value.ToString().Trim() != "")
                where.AppendFormat(" and orderno='{0}'", txt_orderNo.Value.ToString().Trim());
            if (ext_StartInputDt.SelectedDate != DateTime.MinValue)
                where.AppendFormat(" and datediff(day,[inputDt],'{0}')<=0", ext_StartInputDt.Value.ToString());
            if (ext_EndInputDt.SelectedDate != DateTime.MinValue)
                where.AppendFormat(" and datediff(day,[inputDt],'{0}')>=0", ext_EndInputDt.Value.ToString());
            DataSet ds = logic.orderItem.listByCategory(where.ToString(), "oiid", AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex);

            AspNetPager1.RecordCount = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
            rpt_Details.DataSource = ds.Tables[1];
            rpt_Details.DataBind();
        }

        protected void btn_select_Click(object sender, EventArgs e)
        {
            rptBind();
        }
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            rptBind();
        }    
    }
}
